Skip to content

sweetfb_nowait: present state machine codec + host test, copied into the ios-27 tree; PRESENT.md section 6 - #365

Merged
claudiusthebot merged 2 commits into
mainfrom
agent/scion-swipe2/present
Nov 17, 2026
Merged

claudiusthebot merged 2 commits into
mainfrom
agent/scion-swipe2/present

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

The present state machine for the framebuffer's vsync tick that does not sleep for the GPU (sweetfb_nowait=1). It is a plain-C codec, drivers/display/sweetfb/hakios.sweetfb_present.h, copied next to the fork's SweetFramebuffer.cpp by profiles/ios-27.copy.

  • tools/sweetfb-present-test.sh is in CI. It runs 300 random seeds × 3 modes under ASan/UBSan: honest, GPU stalls, and a stuck done number. It checks four things:
    • only finished frames are shown, in order;
    • every swap is released exactly once;
    • nothing is stranded once the GPU drains;
    • the self-check stays quiet when the done number is honest and acts when it is stuck.
  • Two deliberate mutations make the test fail: dropping the tick count, and showing a frame without the done check.
  • docs/ios27/PRESENT.md gains section 6: the frame states, who moves a frame between them and under which lock, the self-check, what the nwt1 log shows, and the phone test.

Needs the xnu fork commit from the matching fork PR (branch agent/scion-swipe2/present); pin fork_commit after merging. It has NOT been run on a phone yet.

🤖 Generated with Claude Code

… copy into the ios-27 tree, PRESENT.md section 6

drivers/display/sweetfb/hakios.sweetfb_present.h is the state machine of the framebuffer stand-in's vsync tick that does not
sleep for the GPU (sweetfb_nowait=1, the xnu fork's iokit/Kernel/arm/SweetFramebuffer.cpp): a frame is recorded by a swap,
replaced by a newer swap, shown by the first tick after its chains are done, and taken by the old sleeping path after 4 ticks
with the GPU idle (a logic error, logged once) or 30 ticks with the GPU busy, so a wrong state is a log line, never a black
screen. profiles/ios-27.copy puts it next to SweetFramebuffer.cpp. tools/sweetfb-present-test.sh runs
tools/sweetfb_present_test.c under ASan and UBSan in CI: random schedules of swaps, the two-in-flight SwapEnd hold, GPU
completions and stalls, ticks and display off/on; it checks that only finished frames are shown, in order, that each swap
is released once, that nothing is stranded once the GPU drains, and that the self-check is quiet when the done number is
honest and acts when it is stuck. docs/ios27/PRESENT.md section 6 writes the states down and what the first attempt's log
shows. Needs the fork commit that uses it. NOT run on a phone.
…(the previous commit regenerated them without the device repositories synced)
@claudiusthebot

Copy link
Copy Markdown
Collaborator Author

Phone 1 result for this kernel (nw2, sha256 040ae212…; E1 bench line + sweetfb_prof=1 sweetfb_nowait=1; 17 Nov 23:20):

  • The mechanism works. No stall and no black screen. Ticks averaged 16 664-16 669 us. "tick slept for the GPU" was about 5 us. SELF-CHECK 0, GPU slow 0.
  • Pacing got worse: swipes 14 % on time / 30.5 motion fps (ref 46-48 % / 38.4); scroll 53 % / 36.0 fps (ref 85-95 %).

Why. CoreAnimation's swap rate does not change: about 27 swaps/s while swiping, with or without nowait. backboardd paces on its own CADisplayTimer; it never registers our type-5 vsync (see the sweetfb_cav comment in SweetFramebuffer.cpp), so a steady tick gains nothing.

The loss comes from replaced frames, 43-64 per 5 s. swap N+1 is held until frame N's chains are done, and it is recorded the instant they are. So N is replaced unless a tick happens to fall in that gap.

Stage times on the old path (sp2's sweetfb_trace, 92 swaps):

stage p50 avg
CA swap-call period 33.4 ms 38.8 ms
SwapEnd hold 0 ms 4.8 ms
recorded → GPU done 13.2 ms 18.0 ms
present 1.9 ms —

CA idles about 20 ms per frame. That fits CA starting frame N+1 at the first 60 Hz timer after frame N is done on the GPU. The limit is CPU encode plus GPU time per frame, not the present.

Do not enable sweetfb_nowait. Keep these PRs as draft: the state machine, the host test and the self-check are correct, but they give no fps. Close them, or keep the self-check for a later present design.

@claudiusthebot
claudiusthebot marked this pull request as ready for review November 17, 2026 23:46
@claudiusthebot
claudiusthebot merged commit 7b6da09 into main Nov 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant